﻿/*

调用方式
$.loading({
delay:1500，//需要多少毫秒呈现
txt:"",//提示框显示的内容
inittype:"fadeIn" //呈现的方式
});

$.complete({
delay:1500，//需要多少毫秒呈现
txt:"",//提示框显示的内容
inittype:"fadeIn" //呈现的方式
},function(){
//此函数回调，通知已完成，可为空
});

$.close({
delay:1500，//需要多少毫秒消失
type:"fadeIn" //呈现的方式
},function(){
//此函数回调，通知已消失，可为空
});
*/
(function ($) {
    jQuery.alert = function (txt) {
        jQuery.complete({
            delay: 1000,
            txt: txt
        });
    }

    jQuery.loading = function (options) {
        options = $.extend({
            delay: 200,
            txt: "",
            inittype: "fadeIn"
        }, options || {});

        var msgContain = "<div id='_showBox' style='";
        msgContain += "background: green url(/Scripts/miniui/themes/icons/wait.gif) no-repeat;";
        msgContain += "font-size:12px; height: 20px; line-height: 20px; text-align: center;";
        msgContain += "color: White; position: absolute; top: 10px; left: 40%;z-index:10000;";
        msgContain += "background-position: 25px 2px; text-indent: 18px; display: none;";
        msgContain += "'></div>";

        $("body").append(msgContain);
        $("#_showBox").html(options.txt).css({ "width": (55 + (options.txt.length * 12)) + "px", "top": $(window).scrollTop() + 10 + "px" });

        switch (options.inittype) {
            case "fadeIn":
                $("#_showBox").fadeIn(options.delay)
                break;
            case "show":
                $("#_showBox").show(options.delay)
                break;
            default:
                $("#_showBox").fadeIn(options.delay)
                break;
        }
    }

    jQuery.complete = function (options, callback) {
        callback = callback || function () { };
        options = $.extend({
            delay: 200,
            txt: "",
            inittype: "fadeIn"
        }, options || {});

        var msgContain = "<div id='_showBox' style='";
        msgContain += "background: green url(/Scripts/miniui/themes/icons/ok.png) no-repeat;";
        msgContain += "font-size:12px; height: 20px; line-height: 20px; text-align: center;";
        msgContain += "color: White; position: absolute; top: 10px; left: 40%;z-index:10000;";
        msgContain += "background-position: 20px 2px; text-indent: 18px; display: none;";
        msgContain += "'></div>";

        $("body").append(msgContain);
        $("#_showBox").html(options.txt).css({ "width": (55 + (options.txt.length * 12)) + "px", "top": $(window).scrollTop() + 10 + "px" });

        switch (options.inittype) {
            case "fadeIn":
                $("#_showBox").fadeIn(options.delay).fadeOut(options.delay, function () { $("#_showBox").remove(); callback });
                break;
            case "show":
                $("#_showBox").show(options.delay).hide(options.delay, function () { $("#_showBox").remove(); callback });
                break;
            default:
                $("#_showBox").fadeIn(options.delay).fadeOut(options.delay, function () { $("#_showBox").remove(); callback });
                break;
        }
    }

    jQuery.close = function (options, callback) {
        callback = callback || function () { };
        options = $.extend({
            type: 'fadeIn',
            delay: 0
        }, options || {});

        switch (options.type) {
            case "fadeIn":
                $("#_showBox").fadeOut(options.delay, function () { $("#_showBox").remove(); callback() });
                break;
            case "hide":
                $("#_showBox").hide(options.delay, function () { $("#_showBox").remove(); callback() });
                break;
            default:
                $("#_showBox").fadeOut(options.delay, function () { $("#_showBox").remove(); callback() });
                break;
        }

    }
})(jQuery);     
